function nodeclick(el, blockid) {
	if ( $(el).attr('class') == 'nodeclose' ) {
		$(el).attr('class', 'nodeopen');
		$('#' + blockid).css('display', 'block');
	}
	else {
		$(el).attr('class', 'nodeclose')
		$('#' + blockid).css('display', 'none');
	}
	return false;
}

function move_items(from, to, deleted) {
	if ( deleted ) {
		$('#' + to).append( $('#' + from + ' option:selected') );
	}
	else {
		$('#' + to).append( $('#' + from + ' option:selected').clone() );
	}

}

function delete_items(from) {
	$('#' + from + ' option:selected').remove();
}

function switch_add() {
	$('#switch option:selected').each( function(i, el) {
			$('#switches_do').append(el);
		});
}


function switch_del() {
	$('#switches_do option:selected').each( function(i, el) {
			$('#switch').append(el);
		});
}

function get_switches(sel) {
	var sw_types = [];
	jQuery('#switch_type option:selected').each( function(i, el) {
			sw_types.push( el.value );
		}
	);

	jQuery.ajax({
		type: 'POST',
		url: '/reports/switches',
		dataType: 'json',
		data: { switch_types: sw_types },
		success: function(data) { 	
				var options;
				$('#switch').empty();
				
				var sw_do = {};
				$('#switches_do option').each( function(i, el) {
						sw_do[ el.value ] = 1;
					}
				);

				for ( var i = 0; i < data.switches.length; i++ ) {
					if( sw_do[ data.switches[i].id ] == undefined ) {
						options = options + '<option value="' + data.switches[i].id + '" onDblClick="switch_add()">' 
							+ data.switches[i].name + '</option>';
					}
				}

				$('#switch').append(options);		

				$('#companies option').remove();
				$('#companies').append('<option value="0">Все</option>');
				for ( key in data.companies ) {
					$('#companies').append('<option value="' + key + '">' + key + '</option>');
				}

				$('#cities option').remove();
				$('#cities').append('<option value="0">Все</option>');
				for ( key in data.cities ) {
					$('#cities').append('<option value="' + key + '">' + key + '</option>');
				}

				$('#obls option').remove();
				$('#obls').append('<option value="0">Все</option>');
				for ( key in data.obls ) {
					$('#obls').append('<option value="' + key + '">' + key + '</option>');
				}

				$('#fos option').remove();
				$('#fos').append('<option value="0">Все</option>');
				for ( key in data.fos ) {
					$('#fos').append('<option value="' + key + '">' + key + '</option>');
				}

				$('#trunks option').remove();
				$('#trunks').append('<option value="0">Все</option>');
				for ( key in data.trunks ) {
					$('#trunks').append('<option value="' + key + '">' + key + '</option>');
				}

			}
		});
}
